#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXSIZE 128

char *gargv[100];
int gargc;


const char* GetUserName()
{
    char* name = getenv("USER");
    if (name == NULL)
        return "None";
    return name;
}

const char* GetHostName()
{
    char* hostname = getenv("HOSTNAME");
    if (hostname == NULL)
        return "None";
    return hostname;
}

const char* GetPwd()
{
    char* pwd = getenv("PWD");
    if (pwd == NULL)
        return "None";
    return pwd;

}

void PrintCommandLine()
{
    // 用户名 主机名 当前路径
    printf("[%s@%s %s]# ", GetUserName(), GetHostName(), GetPwd());
    fflush(stdout);
}

int GetCommandLine(char *commandline, int size)
{
    fgets(commandline, size, stdin);
    commandline[strlen(commandline) - 1] = '\0';

    return strlen(commandline);
}

int main()
{
    while(1)
    {
        char command_line[MAXSIZE] = {0};
        // 1.打印字符串
        PrintCommandLine();
        // 2.获取用户输入
        if (0 == GetCommandLine(command_line, sizeof(command_line)))
                continue;
        
        printf("%s\n", command_line);
        // 3.解析命令
        
    }
    return 0;
}
